/**
 * 
 */
package net.extrema.bbm.rest;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import net.extrema.bbm.Constants;
import net.extrema.bbm.db.Bus;
import net.extrema.bbm.db.Seat;

/**
 * @author Marco Libanori
 */
@Path("/bus")
public class BusRestService {

	@GET
	@Path("/get/{id}")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getBusById(@PathParam("id") Integer id) {

		EntityManagerFactory emf = Persistence
				.createEntityManagerFactory(Constants.PERSISTENCE_UNIT);
		EntityManager em = emf.createEntityManager();
		Bus bus = em.find(Bus.class, id);

		return Response.status(200).entity(bus).build();
	}

	@POST
	@Path("/save")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response save(Bus bus) {

		EntityManagerFactory emf = Persistence
				.createEntityManagerFactory(Constants.PERSISTENCE_UNIT);
		EntityManager em = emf.createEntityManager();

		EntityTransaction et = em.getTransaction();

		et.begin();
		em.persist(bus);
		et.commit();

		return Response.status(200).entity(bus).build();
	}

	@GET
	@Path("/test")
	@Produces(MediaType.APPLICATION_JSON)
	public Response test() {

		// EntityManagerFactory emf =
		// Persistence.createEntityManagerFactory(Constants.PERSISTENCE_UNIT);
		// EntityManager em = emf.createEntityManager();
		// Bus bus = em.find(Bus.class, id);

		List<Bus> busArray = new ArrayList<Bus>();

		Bus bus = new Bus();
		bus.setId(1);
		List<Seat> seats = bus.getSeats();

		Seat seat;

		seat = new Seat();
		seat.setFirstName("Willie");
		seat.setLastName("Williams");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Adam");
		seat.setLastName("Adams");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Doris");
		seat.setLastName("Davis");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Jeremy");
		seat.setLastName("Butler");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Andrew");
		seat.setLastName("Jackson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Wanda");
		seat.setLastName("Jones");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Brian");
		seat.setLastName("Rivera");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Joyce");
		seat.setLastName("Coleman");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Carolyn");
		seat.setLastName("Young");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("John");
		seat.setLastName("Nelson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Jerry");
		seat.setLastName("Harris");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Carl");
		seat.setLastName("Collins");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Gloria");
		seat.setLastName("Howard");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Joshua");
		seat.setLastName("Barnes");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Randy");
		seat.setLastName("Turner");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Chris");
		seat.setLastName("Rogers");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Russell");
		seat.setLastName("Long");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Anna");
		seat.setLastName("Jenkins");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Theresa");
		seat.setLastName("Morris");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Jean");
		seat.setLastName("Walker");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Billy");
		seat.setLastName("Simmons");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Mary");
		seat.setLastName("Martin");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Dennis");
		seat.setLastName("Richardson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Gerald");
		seat.setLastName("Hall");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Donald");
		seat.setLastName("Moore");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Nancy");
		seat.setLastName("Lee");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Bobby");
		seat.setLastName("Brown");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Virginia");
		seat.setLastName("Reed");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Dorothy");
		seat.setLastName("Thomas");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Brenda");
		seat.setLastName("Murphy");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Debra");
		seat.setLastName("Clark");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Catherine");
		seat.setLastName("Lewis");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Ashley");
		seat.setLastName("Mitchell");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Douglas");
		seat.setLastName("Kelly");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Larry");
		seat.setLastName("Washington");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Christopher");
		seat.setLastName("Roberts");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Elizabeth");
		seat.setLastName("Hughes");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Samuel");
		seat.setLastName("Edwards");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		/* seat = new Seat();
		seat.setFirstName("Helen");
		seat.setLastName("Baker");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Jonathan");
		seat.setLastName("Hill");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Ernest");
		seat.setLastName("Henderson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("William");
		seat.setLastName("Peterson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Alice");
		seat.setLastName("Miller");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Jimmy");
		seat.setLastName("Gonzales");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Sandra");
		seat.setLastName("Martinez");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Lois");
		seat.setLastName("Russell");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Kenneth");
		seat.setLastName("Garcia");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Jack");
		seat.setLastName("Stewart");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Carol");
		seat.setLastName("White");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Patrick");
		seat.setLastName("Torres");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Ann");
		seat.setLastName("Rodriguez");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Evelyn");
		seat.setLastName("Cooper");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Steven");
		seat.setLastName("Taylor");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Shawn");
		seat.setLastName("Campbell");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Kathleen");
		seat.setLastName("James");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Tina");
		seat.setLastName("Cox");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Phillip");
		seat.setLastName("Allen");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Nicholas");
		seat.setLastName("Wood");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Andrea");
		seat.setLastName("Gray");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Matthew");
		seat.setLastName("Evans");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Amy");
		seat.setLastName("Phillips");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Keith");
		seat.setLastName("Bailey");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Henry");
		seat.setLastName("Thompson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Michelle");
		seat.setLastName("Powell");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Walter");
		seat.setLastName("King");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Peter");
		seat.setLastName("Griffin");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("George");
		seat.setLastName("Bryant");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Teresa");
		seat.setLastName("Price");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Barbara");
		seat.setLastName("Perry");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Earl");
		seat.setLastName("Watson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Rose");
		seat.setLastName("Ramirez");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Kelly");
		seat.setLastName("Bell");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Judith");
		seat.setLastName("Brooks");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Deborah");
		seat.setLastName("Lopez");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Amanda");
		seat.setLastName("Wright");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Joseph");
		seat.setLastName("Robinson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Anthony");
		seat.setLastName("Sanders");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Albert");
		seat.setLastName("Diaz");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Cynthia");
		seat.setLastName("Cook");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Jose");
		seat.setLastName("Anderson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Arthur");
		seat.setLastName("Hernandez");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Carlos");
		seat.setLastName("Foster");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Kevin");
		seat.setLastName("Scott");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Emily");
		seat.setLastName("Parker");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Mark");
		seat.setLastName("Gonzalez");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Denise");
		seat.setLastName("Alexander");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Sara");
		seat.setLastName("Perez");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Stephanie");
		seat.setLastName("Bennett");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Karen");
		seat.setLastName("Wilson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Irene");
		seat.setLastName("Flores");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Ruth");
		seat.setLastName("Green");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Jacqueline");
		seat.setLastName("Sanchez");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Thomas");
		seat.setLastName("Carter");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Melissa");
		seat.setLastName("Ross");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Victor");
		seat.setLastName("Ward");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Alan");
		seat.setLastName("Patterson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Rebecca");
		seat.setLastName("Morgan");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Diane");
		seat.setLastName("Smith");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName("Frank");
		seat.setLastName("Johnson");
		seat.setPhone("555-5555555");
		seat.setSchedule(new Date());
		seats.add(seat); */

		seat = new Seat();
		seat.setFirstName(null);
		seat.setLastName(null);
		seat.setPhone(null);
		seat.setSchedule(null);
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName(null);
		seat.setLastName(null);
		seat.setPhone(null);
		seat.setSchedule(null);
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName(null);
		seat.setLastName(null);
		seat.setPhone(null);
		seat.setSchedule(null);
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName(null);
		seat.setLastName(null);
		seat.setPhone(null);
		seat.setSchedule(null);
		seats.add(seat);

		seat = new Seat();
		seat.setFirstName(null);
		seat.setLastName(null);
		seat.setPhone(null);
		seat.setSchedule(null);
		seats.add(seat);

		busArray.add(bus);

		return Response.status(200).entity(busArray).build();
	}
}
